package cn.yh.springbootjwt.config;

import cn.yh.springbootjwt.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class AuthInterceptorConfig implements WebMvcConfigurer {
    @Autowired
    private AuthInterceptor authInterceptor;

    String[] xiaomiPaths = {
            "/category/list",
            "/product/list",
            "/product/find",
            "/user/create",
    };

    //排除swagger、knife4j文档的拦截
    String[] excludePatterns = new String[]{
            "/*.html",
            "/**/*.html",
            "/**/*.css",
            "/**/*.js",
            "/**/*.ico",
            "/swagger-resources/**",
            "/*/api-docs",
            "/swagger-ui.html"
    };

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor)
                .excludePathPatterns(
                        "/user/login",
                        "/error")
                .excludePathPatterns(xiaomiPaths)
                .excludePathPatterns(excludePatterns)
                .addPathPatterns("/**");

    }
}

